package encome.work.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import encome.work.dao.HelpSeeker;
import encome.work.dao.ResponseResult;
import encome.work.utils.StatusCode;
import encome.work.service.HelpSeekerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/helpseeker")
public class HelpSeekerController {

    @Resource
    private HelpSeekerService helpSeekerService;

    /**
     * 新增需求表
     */
    @PostMapping("/insert")
    public ResponseResult<String> add(@RequestBody HelpSeeker helpSeeker){
        helpSeekerService.add(helpSeeker);
        return new ResponseResult<>(StatusCode.OK, "新增需求表成功");
    }

    /**
     * 更新需求表
     */
    @PutMapping("/update/{id}")
    public ResponseResult<String> update(@PathVariable("id") Long id, @RequestBody HelpSeeker helpSeeker){
        helpSeeker.setId(id);
        helpSeekerService.update(helpSeeker);
        return new ResponseResult<>(StatusCode.OK, "修改需求表成功");
    }

    /**
     * 删除需求表
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult<String> delete(@PathVariable("id") Long id){
        helpSeekerService.delete(id);
        return new ResponseResult<>(StatusCode.OK, "删除需求表成功");
    }

    /**
     * 多条件分页查询需求表
     */
    @PostMapping("/search/{page}/{size}")
    public ResponseResult<Page<HelpSeeker>> findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size,
                                                 @RequestBody HelpSeeker helpSeeker){
        Page<HelpSeeker> helpSeekerPage= helpSeekerService.findPage(helpSeeker, page, size);
        return new ResponseResult<>(StatusCode.OK, "查询成功", helpSeekerPage);
    }
    /**
     * 根据id查询需求表
     */
    @GetMapping("/{id}")
    public ResponseResult<HelpSeeker> findById(@PathVariable("id") Long id){
        HelpSeeker helpSeeker = helpSeekerService.findById(id);
        return new ResponseResult<>(StatusCode.OK, "查询成功", helpSeeker);
    }

    /**
     * 默认分页查询需求表
     */
    @GetMapping("/search/{page}/{size}")
    public ResponseResult<Page<HelpSeeker>> findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        Page<HelpSeeker> helpSeekerPage = helpSeekerService.findPage(page, size);
        return new ResponseResult<>(StatusCode.OK,"查询成功", helpSeekerPage);
    }
}
